package com.whfc.iot.config;

import com.whfc.common.file.FileHandler;
import com.whfc.common.file.FileHandlerStrategy;
import com.whfc.common.file.properties.AliyunFileProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description 阿里云配置
 * @Author hw
 * @Date 2021/4/10 10:30
 * @Version 1.0
 */
@Configuration
@ConditionalOnProperty(name = "aliyun-oss.type", havingValue = "aliyunOss", matchIfMissing = true)
public class AliyunOssConfig {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Bean("aliyunFileProperties")
    @ConfigurationProperties(prefix = "aliyun-oss")
    public AliyunFileProperties aliyunFileProperties() {
        return new AliyunFileProperties();
    }

    @Bean
    public FileHandler fileHandler(@Qualifier("aliyunFileProperties") AliyunFileProperties aliyunFileProperties) {
        logger.info("加载阿里云配置：{}", aliyunFileProperties);
        return FileHandlerStrategy.FileHandlerStrategy(aliyunFileProperties);
    }
}
